#include "StdAfx.h"
#include "ExtensionMapper.h"
#include "AnalogPhone.h"

namespace DBLayer {
/*CExtensionMapper::CExtensionMapper(void)
{
}

CExtensionMapper::~CExtensionMapper(void)
{
}*/
/*bool CExtensionMapper::loadData(int type,CTinyDBInterface* DBIF)
{
	m_DBType = type;
	m_DBIF = DBIF;
	m_MapperData.clear();
	if(type == MYSQLDB)
	{
		try{
			sql::ResultSet * rs = (sql::ResultSet*)DBIF->executeSQL(std::string("SELECT extnumber, extSeq FROM extension")+m_filterStr );
			if(rs == NULL)
				return false;
			while (rs->next())
			{
				//process data
				std::string extnumber = rs->getString("extnumber");
				std::string extSeq = rs->getString("extSeq");
				std::map<std::string,std::string> tempMap;
				tempMap.insert(std::pair<std::string,std::string>("extnumber",extnumber));
				tempMap.insert(std::pair<std::string,std::string>("extSeq",extSeq));
				m_MapperData.push_back(tempMap);
			}
		}
		catch (sql::SQLException &e) {
			std::string err =  e.what();
			return false;
		}
	}


	return true;
}*/

	std::vector<HAL::CTinyDevice*>* CExtensionMapper::GetAll()
	{
		if(m_DBType == DBTYPE_MYSQL)
		{
			sql::ResultSet * rs = executeSql(selectStr);
			if(rs == NULL)
				return NULL;

			std::vector<HAL::CTinyDevice*>* devices = new std::vector<HAL::CTinyDevice*>();
			while(rs->next())
			{
				HAL::CAnalogPhone* phone = new HAL::CAnalogPhone();
				phone->extNumber = rs->getString("extnumber");
				phone->m_CardID = rs->getInt("cardid");
				phone->m_ChannelID = rs->getInt("channelID");
				phone->m_CardSN = rs->getString("cardsn");
				phone->m_CardType = rs->getString("cardname");
				devices->push_back((HAL::CAnalogPhone*)phone);
			}
			return devices;
		}
		return NULL;
	}
}